package gazzera.swing.network;

/* 
 * ColorRenderer.java (compiles with releases 1.2, 1.3, and 1.4) is used by 
 * TableDialogEditDemo.java.
 */

import gazzera.node.core.*;
import gazzera.swing.model.*;

import java.awt.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;


public class GidRenderer  extends JLabel
                           implements TableCellRenderer {
    Border unselectedBorder = null;
    Border selectedBorder = null;
    boolean isBordered = true;

    public GidRenderer(boolean isBordered) {
        super();
    	this.isBordered = isBordered;
        setOpaque(true); //MUST do this for background to show up.
        //Font f = getFont();
	    //setFont(f.deriveFont(f.getStyle() | Font.BOLD));
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object o,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        
    	Connection c = (Connection)o;
    	String x = "";
    	if(c.onlineStatus == OnlineStatus.CONNECTING)
    	{
    		x = "<small style=\"color:#66aa66\"> connecting...</small>";
    	}
    	String s = "<html>"+c.nickname+x+"<br><small style=\"color:#d0d0d0\">"+c.hash+"</small></html>";
    	if(isSelected)
    	{
    		setBackground(table.getSelectionBackground());//new Color(0xb8,0xcf,0xe5));
    	}
    	else
    	{
    		setBackground(table.getBackground());
    	}
    	setForeground(isSelected ? Color.WHITE : Color.BLACK);
        setText(s);
        
        /*
        if (isBordered) {
            if (isSelected) {
                if (selectedBorder == null) {
                    selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
                                              table.getSelectionBackground());
                }
                setBorder(selectedBorder);
            } else {
                if (unselectedBorder == null) {
                    unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
                                              table.getBackground());
                }
                setBorder(unselectedBorder);
            }
        }
        
        setToolTipText("RGB value: " + newColor.getRed() + ", "
                                     + newColor.getGreen() + ", "
                                     + newColor.getBlue());
                                     */
        return this;
    }
}
